package priv.pront.code.lanqiao.competition.course.date0327;

import java.util.Arrays;
import java.util.Scanner;

public class 小朋友排队 {
    static int[] h;
    static int[] cnt;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        h = new int[n];
        cnt = new int[n];
        int max = 0;
        for (int i = 0; i < n; i++) {
            h[i] = scanner.nextInt();
            max = Math.max(max, h[i]);
        }
        BinaryTest_2 bi = new BinaryTest_2(max + 1);
//        从左往右扫描
        for (int i = 0; i < n; i++) {
//            在相应的位置计数变为1，其实就是用树状数组维护数据出现的个数
            bi.update(h[i] + 1,1);
//            小于等于h[i] + 1的个数
            int sum = bi.sum(h[i] + 1);
//            当前数据左侧比数据大的数的个数
            cnt[i] += (i + 1) - sum;
        }
        Arrays.fill(BinaryTest_2.c,0);
//        从右往左扫描
        for (int i = n - 1; i >= 0; i--) {
            bi.update(h[i] + 1, 1);
            int sum = bi.sum(h[i] + 1);
//            上一步求出>=h的个数，扣掉自己的个数，得到的就是当前右侧比数据小的数的个数
            int self = bi.sum(h[i] + 1) -bi.sum(h[i]);
            cnt[i] += sum -self;
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += ((long) cnt[i] * (cnt[i] + 1) / 2);
        }
        System.out.println(ans);
    }

    static class BinaryTest_2 {

        static int[] c;
        int n;

        public BinaryTest_2(int n) {
            this.n = n;
            c = new int[n + 1];
        }

        public int lowBit(int x){
            return x & -x;
        }

        public void update(int p, int d) {
            for (; p <= n; p += lowBit(p)) {
                c[p] += d;
            }
        }

        public int sum(int p){
            int ans = 0;
            for (; p > 0; p -= lowBit(p)) {
                ans += c[p];
            }
            return ans;
        }
    }
}
